package com.example.pixelyear.utils.dialog

import com.example.pixelyear.Interface.OnBackUpClickListener
import com.example.pixelyear.Interface.OssType
import com.example.pixelyear.R
import com.example.pixelyear.ui.base.BaseActivity
import com.example.pixelyear.utils.extension.setOnDoubleClickListener
import com.example.pixelyear.utils.extension.setVisi
import kotlinx.android.synthetic.main.dialog_backup.view.*

class BackupDialog(val context: BaseActivity) : BaseDialog(context) {

    private var backUpClickListener: OnBackUpClickListener? = null
    private var ossType = OssType.BackUp
    override fun getLayoutID(): Int {
        return R.layout.dialog_backup
    }

    override fun initAny() {
        rootView.Dialog_BackUp_LocalRestore.setOnDoubleClickListener {
            backUpClickListener?.local(ossType)
            dismiss()
        }

        rootView.Dialog_BackUp_NetWork.setOnDoubleClickListener {
            backUpClickListener?.netWork(ossType)
            dismiss()
        }

        rootView.Dialog_BackUp_NetWorkChangePhone.setOnDoubleClickListener {
            backUpClickListener?.netWorkChangePhone(ossType)
            dismiss()
        }
    }

    fun show(type: OssType) {
        super.show()
        this.ossType = type
        rootView.Dialog_BackUp_LocalRestore.text = "本地${if (ossType == OssType.BackUp) "备份" else "还原"}"
        rootView.Dialog_BackUp_NetWork.text = "网络${if (ossType == OssType.BackUp) "备份" else "还原（未换手机）"}"
        rootView.Dialog_BackUp_NetWorkChangePhone.setVisi(ossType == OssType.Restore)
        rootView.Dialog_BackUp_NetWorkChangePhone.text = "网络还原（更换手机）"
    }

    fun setListener(listener: OnBackUpClickListener) {
        this.backUpClickListener = listener
    }

}